package chances.epg.commons.utils;

import org.apache.commons.lang.math.RandomUtils;

public class CommonUtils {

	/**
	 * 生成随机序列.
	 * 
	 * @param total
	 * @return
	 */
	public static int[] getRandomSequence(int total) {
		int[] sequence = new int[total];
		int[] output = new int[total];

		for (int i = 0; i < total; i++) {
			sequence[i] = i;
		}

		int end = total - 1;

		for (int i = 0; i < total; i++) {
			int num = RandomUtils.nextInt(end + 1);
			output[i] = sequence[num];
			sequence[num] = sequence[end];
			end--;
		}

		return output;
	}

}
